package com.example.v2.component.vault;

import org.springframework.cloud.vault.config.VaultGenericBackendProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.vault.core.VaultTemplate;
import org.springframework.vault.core.VaultTransitOperations;

import javax.annotation.Resource;

@Configuration
public class VaultTool {

    @Resource
    private VaultTemplate vaultTemplate;
    @Resource
    private VaultGenericBackendProperties genericBackendProperties;

    public String decrypt(String ciphertext) {
        VaultTransitOperations transitOperations = vaultTemplate.opsForTransit(genericBackendProperties.getBackend());
        return transitOperations.decrypt(genericBackendProperties.getApplicationName(), ciphertext);
    }


}
